package com.example.gateway;

import com.alibaba.nacos.common.utils.MD5Utils;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * @author karidyang
 */
@Slf4j
public class SignUtil {

    public static String sing(String signKey, Map<String, String> params) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        sb.append(signKey);
        log.info("sign str = " + sb.toString());
        return  MD5Utils.md5Hex(sb.toString(), StandardCharsets.UTF_8.name());
    }

}
